package com.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.R;
import com.example.dto.DishDto;
import com.example.entity.Category;
import com.example.entity.Dish;
import com.example.service.DishFlavorService;
import com.example.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜品管理 前端控制器
 * </p>
 *
 * @author lw
 * @since 2023-01-31
 */
@RestController
@RequestMapping("/dish")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;
    @Autowired
    private DishFlavorService dishFlavorService;

    @PostMapping
    public R<String> save(@RequestBody DishDto dishDto){

        return dishService.saveDish(dishDto);
    }

    @GetMapping("/page")
    public R<Page> getPage(int page, int pageSize, String name){

        return dishService.getPage(page,pageSize,name);
    }
    @GetMapping("/{id}")
    public R<DishDto> get(@PathVariable Long id){
        return R.success(dishService.getDishById(id));
    }
    @PutMapping
    public R<String> update(@RequestBody DishDto dishDto){

        return dishService.updateDish(dishDto);
    }
    @GetMapping("/list")
    public R<List<DishDto>> findOne(Dish dish){

         return dishService.findOne(dish);
    }
    @DeleteMapping
    public R<String> deleteCategory(@RequestParam List<Long> ids){
        return dishService.delete(ids);
    }
}

